package com.taoym.voucher.xcx.service.impl;

import com.taoym.voucher.common.constant.DicEnumTypeConstant;
import com.taoym.voucher.common.enums.*;
import com.taoym.voucher.xcx.entity.vo.XcxGetDicEnumVO;
import com.taoym.voucher.xcx.service.XcxDicEnumService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @coder taoym
 * @datetime 2021/6/5 10:18
 * @desc 枚举字典服务接口实现类
 */
@Service
public class XcxDicEnumServiceImpl implements XcxDicEnumService {

    @Override
    public List<XcxGetDicEnumVO> getDicEnum(String type) {

        EnumsCommon[] enumsCommons = null;
        if (type.equals(DicEnumTypeConstant.ACTIVITY_ORDER_STATUS)) {
            enumsCommons = ActivityOrderStatusEnum.values();
        } else if (type.equals(DicEnumTypeConstant.DATE_CONDITION)) {
            enumsCommons = DateConditionEnum.values();
        } else if (type.equals(DicEnumTypeConstant.TEXT_TYPE_ENUM)) {
            enumsCommons = TextTypeEnum.values();
        } else if (type.equals(DicEnumTypeConstant.ORDER_BUY_TYPE_ENUM)) {
            enumsCommons = OrderBuyTypeEnum.values();
        }
        if (ObjectUtils.isEmpty(enumsCommons)) {
            return null;
        }
        List<XcxGetDicEnumVO> xcxGetDicEnumVOS = new ArrayList<>(enumsCommons.length);
        for (EnumsCommon value : enumsCommons) {
            XcxGetDicEnumVO xcxGetDicEnumVO = new XcxGetDicEnumVO();
            xcxGetDicEnumVO.setCode(value.getCode());
            xcxGetDicEnumVO.setMsg(value.getMsg());
            xcxGetDicEnumVOS.add(xcxGetDicEnumVO);
        }

        return xcxGetDicEnumVOS;
    }
}
